unit Unit_Base;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Mask, DBCtrls, Grids, DBGrids, ComCtrls, Buttons,
  ToolWin, ExtCtrls;

type
  Tfrm_Base = class(TForm)
    ControlBar: TControlBar;
    ToolBar2: TToolBar;
    btnAdd: TSpeedButton;
    btnDelete: TSpeedButton;
    btnSave: TSpeedButton;
    btnCancel: TSpeedButton;
    ToolButton1: TToolButton;
    btnClose: TSpeedButton;
    GroupBox2: TGroupBox;
    DBGrid1: TDBGrid;
    GroupBox1: TGroupBox;
    DBEdit1: TDBEdit;
    DBText1: TDBText;
    procedure btnAddClick(Sender: TObject);
    procedure btnCloseClick(Sender: TObject);
    procedure btnCancelClick(Sender: TObject);
    procedure btnSaveClick(Sender: TObject);
    procedure DBEdit1KeyPress(Sender: TObject; var Key: Char);
    procedure FormCreate(Sender: TObject);
  private
    OldGridWnd:TWndMethod;
    procedure NewGridWnd(var Message:TMessage);
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frm_Base: Tfrm_Base;

implementation


{$R *.dfm}

procedure Tfrm_Base.btnAddClick(Sender: TObject);
begin
  GroupBox2.Enabled:=false;
  btnAdd.Enabled:=false;
  btnDelete.Enabled:=false;
  btnSave.Enabled:=true;
  btnCancel.Enabled:=true;
end;

procedure Tfrm_Base.btnCloseClick(Sender: TObject);
begin
  Close;
end;

procedure Tfrm_Base.btnCancelClick(Sender: TObject);
begin
  GroupBox2.Enabled:=true;
  btnAdd.Enabled:=true;
  btnDelete.Enabled:=true;
  btnSave.Enabled:=false;
  btnCancel.Enabled:=false;
end;

procedure Tfrm_Base.btnSaveClick(Sender: TObject);
begin
  GroupBox2.Enabled:=true;
  btnAdd.Enabled:=true;
  btnDelete.Enabled:=true;
  btnSave.Enabled:=false;
  btnCancel.Enabled:=false;
end;

procedure Tfrm_Base.DBEdit1KeyPress(Sender: TObject; var Key: Char);
begin
  GroupBox2.Enabled:=false;
  btnAdd.Enabled:=false;
  btnDelete.Enabled:=false;
  btnSave.Enabled:=true;
  btnCancel.Enabled:=true;
end;

procedure Tfrm_Base.FormCreate(Sender: TObject);
begin
  OldGridWnd := DBGrid1.WindowProc;
  DBGrid1.WindowProc := NewGridWnd;
end;

procedure Tfrm_Base.NewGridWnd(var Message: TMessage);
var
  IsNeg:Boolean;
begin
  if Message.Msg = WM_MOUSEWHEEL then
  begin
    IsNeg := Short(Message.WParamHi)   <   0;
    if (IsNeg) and (not DBGrid1.DataSource.DataSet.Eof) then
      DBGrid1.DataSource.DataSet.MoveBy(1)
    else if (IsNeg = false) and (not DBGrid1.DataSource.DataSet.Bof) then
      DBGrid1.DataSource.DataSet.MoveBy(-1);
  end
  else OldGridWnd(Message);
end;

end.
